我想将此附加到文本输入而不是段落标记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 :(得分:0)
试试这个考试
<!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>
答案 1 :(得分:0)
我认为您需要使用有效的选择器,$(this).find('Yield')
应该是$(this).find('#Yield')
,如果您想要输入(不确定我理解您的问题,但我认为这就是您想要的):
$('#Yield').append('<p><h6>Servings: <input type="text" value="' + yield + '"> servings'+ '</h6></p>')