0
我有一個具有不同控件的網頁。我必須通過按鈕單擊某個特定的div元素的值來獲取html源代碼。使用jQuery獲取填充表單的HTML代碼
jQuery .html()方法給了我沒有值的控件的html源碼,但我需要html源碼和用戶選擇的值。
我有一個具有不同控件的網頁。我必須通過按鈕單擊某個特定的div元素的值來獲取html源代碼。使用jQuery獲取填充表單的HTML代碼
jQuery .html()方法給了我沒有值的控件的html源碼,但我需要html源碼和用戶選擇的值。
嘗試遍歷每個<input>
並在訪問html之前將其設置爲value
屬性爲其DOM值。
的jsfiddle:http://jsfiddle.net/AWK9S/3/
$('form input').each(function()
{
this.setAttribute('value',this.value);
if (this.checked)
this.setAttribute('checked', 'checked');
else
this.removeAttribute('checked');
});
$('form select').each(function()
{
var index = this.selectedIndex;
var i = 0;
$(this).children('option').each(function()
{
if (i++ != index)
this.removeAttribute('selected');
else
this.setAttribute('selected','selected');
});
});
$('form textarea').each(function()
{
$(this).html($(this).val());
});
的jsfiddle:http://jsfiddle.net/AWK9S/3/
我會用'$( ':輸入')',而不是爲'input'不匹配''
什麼選擇和其他元素... – Brij 2010-09-22 07:56:37
現在'