2013-04-30 125 views
0

我希望把這段文字輸入不是段落標記p我嘗試,但我不能讓它追加到文本輸入

我追加碼

$(req.responseText).find('GetRecipeDetailResponse').each(function(){//Get the servings/yield 
    var yield = $(this).find('Yield').text(); 
    $('#Yield').append('<p><h6>Servings: ' + yield + " servings"+ '</h6></p>') 
    $('#Yield').fieldcontain('refresh') 
}); 

HTML代碼:

<div data-role="fieldcontain" id="Yield"><!--Yield--> 

    </div> 
+0

請解釋*不是p ..我試試* – hjpotter92 2013-04-30 05:44:53

+0

對不起,錯別字錯誤 – 2013-04-30 05:48:07

回答

0

我認爲你需要使用一個有效的選擇,$(this).find('Yield')也許應該是$(this).find('#Yield'),如果你想讓它在輸入(不知道我理解你的問題,但我認爲這是你想要的):

$('#Yield').append('<p><h6>Servings: <input type="text" value="' + yield + '"> servings'+ '</h6></p>') 
+0

嗯。謝謝。但是,我如何編輯文本? – 2013-04-30 05:53:54

+0

你想要編輯什麼文字? – dave 2013-04-30 05:54:59

+0

收益值。我希望收益率作爲主要價值,但可以改變。 – 2013-04-30 05:55:34

0

試試這個Examble

<!DOCTYPE html> 
<html> 
<head> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> 
</script> 
<script> 
$(document).ready(function(){ 
    $("#btn1").click(function(){ 
    $("p").append(" <b>Appended text</b>."); 
    }); 
    $("#btn2").click(function(){ 
    $("ol").append("<li>Appended item</li>"); 
    }); 
}); 
</script> 
</head> 
<body> 

<p>This is a paragraph.</p> 
<p>This is another paragraph.</p> 
<ol> 
<li>List item 1</li> 
<li>List item 2</li> 
<li>List item 3</li> 
</ol> 

<button id="btn1">Append text</button> 
<button id="btn2">Append list item</button> 

</body> 
</html>