2014-07-09 77 views
-2

當我點擊一個HTML按鈕時,源代碼是否可能改變?當您點擊HTML按鈕時,您可以更改HTML源代碼嗎?

例如,如果有對HTML這樣一行

<p>The button was pressed <span id="displayCount">0</span> times.</p> 

是否有可能因此說

<p>The button was pressed <span id="displayCount">1</span> times.</p> 

,當我讀到的源代碼或頁面源去改變它?

我正在使用Arduino發送一個HTTP請求來獲取頁面的HTML代碼。因此,當我們查看頁面源代碼時,Arduino基本上獲得了我們看到的內容。與「檢查元素」有何不同?

+3

具有u嘗試任何事情? – iJade

+0

是的,當您使用$('#displayCount')。html('1')更改html值時,它實際上會在html源代碼中更改。 – nsthethunderbolt

+0

請參閱http://jsfiddle.net/HLypn/2/ –

回答

0
$("input").click(function(){ 
    $("#displayCount").html("1"); 
}); 

使用jQuery與http://api.jquery.com/click/

編輯:

如果你想要做一個動態的增量,做由他人提供的:

$("input").click(function(){ 
    var oldcount = parseInt($("#displayCount").html()); 
    $("#displayCount").html(oldcount++); 
}); 
0

你問之前,請搜索新問題。

<button>click to up the count</button> 
<p>The button was pressed <span id="displayCount">0</span> times.</p> 
<script> 
    $('button').click(function() { 
     var newCount = parseInt($('#displayCount').text()) + 1; 
     $('#displayCount').text(newCount); 
    }); 
</script> 

這裏是小提琴:http://jsfiddle.net/Fe5e5/

0

怎麼樣呢?

$("#button").click(function() { 
    $("#displayCount").html(parseInt($("#displayCount").text()) + 1); 
    return false; 
}); 
0

只需複製該代碼

<script> 
var count = 0; 
function increment_Count(){ 
    count +=1; 
    document.getElementById('displayCount').innerHTML=count; 
} 
</script> 
<p>The button was pressed <span id="displayCount">0</span> times.</p> 
<input type="button" onclick="increment_Count();" value="Click To Increment"/> 
相關問題