admin管理员组文章数量:1391925
I am using jQuery for the first time. I've been searching a lot but have not gotten the answer.
I want to insert an input Type at id="star" and with value="score Star" but I'm not able to do that. Score returns the numeric value. I think the problem is in the value attribute, but I don't know where. Thanks In Advance.
Here's the code:
<script type="text/javascript">
$(function() {
$('#click').raty({
click: function(score) {
document.getElementById('star').innerHTML="<input type='text' name='type' value='"score+ "' Star >";
//alert( 'score: ' + score);
}
});
});
</script>
<label>Deal Type:</label>
<div id="click"></div><span id="star"></span></div>
I am using jQuery for the first time. I've been searching a lot but have not gotten the answer.
I want to insert an input Type at id="star" and with value="score Star" but I'm not able to do that. Score returns the numeric value. I think the problem is in the value attribute, but I don't know where. Thanks In Advance.
Here's the code:
<script type="text/javascript">
$(function() {
$('#click').raty({
click: function(score) {
document.getElementById('star').innerHTML="<input type='text' name='type' value='"score+ "' Star >";
//alert( 'score: ' + score);
}
});
});
</script>
<label>Deal Type:</label>
<div id="click"></div><span id="star"></span></div>
Share
edited Dec 13, 2012 at 18:36
Corey Adler
16.2k18 gold badges69 silver badges80 bronze badges
asked Dec 13, 2012 at 18:11
Vaibhav AgarwalVaibhav Agarwal
581 silver badge9 bronze badges
1
- value='"score+ "' <--- you miss a '+' – Pablo Martinez Commented Dec 13, 2012 at 18:14
4 Answers
Reset to default 2You're not writing the code correctly
.innerHTML="<input type='text' name='type' value='"score+ "' Star >";
It should be
.innerHTML="<input type='text' name='type' value='"+score+" Star' >";
You're not concatenating the string, or quoting the value correctly
.innerHTML="<input type='text' name='type' value='"score+ "' Star >";
should be
.innerHTML="<input type='text' name='type' value='" + score + " Star' >";
<script type="text/javascript">
$(function() {
$('#click').raty({
click: function(score) {
document.getElementById('star').innerHTML="<input type='text' name='type' value='"+score+ " Star'>";
//alert( 'score: ' + score);
}
});
});
</script>
<label>Deal Type:</label>
<div id="click"></div><span id="star"></span></div>
A better approach is to actually create an input DOM object and append it:
$('#star').append($('<input/>').attr({
type: "text",
name: "type",
value: score + " Star"
}));
本文标签: javascriptInsert Input Box Using innerHTML property of jQueryStack Overflow
版权声明:本文标题:javascript - Insert Input Box Using .innerHTML property of jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744651087a2617687.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论