我需要在我的代码中添加一个 HTML 锚。第一个代码工作正常,但不包含我需要的锚标记。但是第二个失败了:
这很好用,不包括:
<script type='text/javascript'>//<![CDATA[
$('#Quantity').keyup(function () {
var textualValue = $(this).val();
var numericValue = parseInt(textualValue, 10);
if (!isNaN(numericValue)) {
modifyDOMWithNumber(numericValue);
} else {
modifyDOMWithNumber(0);
}
});
function modifyDOMWithNumber(number) {
var ul = $('ul#ListToAlter').empty();
var item;
for (var i = 1; i <= number; i++) {
item = $("<li>");
if (i == 1) {
item.text("Options for your 1st $Name");
}else if(i == 2) {
item.text("Options for your 2nd $Name");
}else if(i == 3) {
item.text("Options for your 3rd $Name");
} else {
item.text("Options for your number " + i + "th $Name");
}
ul.append(item);
}
}
//]]>
</script>
这失败了,确实包括:
<script type='text/javascript'>//<![CDATA[
$('#Quantity').keyup(function () {
var textualValue = $(this).val();
var numericValue = parseInt(textualValue, 10);
if (!isNaN(numericValue)) {
modifyDOMWithNumber(numericValue);
} else {
modifyDOMWithNumber(0);
}
});
function modifyDOMWithNumber(number) {
var ul = $('ul#ListToAlter').empty();
var item;
for (var i = 1; i <= number; i++) {
item = $("<li>");
if (i == 1) {
item.html("<a>Options for your 1st $Name</a>");
}else if(i == 2) {
item.html("<a>Options for your 2nd $Name</a>");
}else if(i == 3) {
item.html("<a>Options for your 3rd $Name</a>");
} else {
item.html("<a>Options for your number " + i + "th $Name</a>");
}
ul.append(item);
}
}
//]]>
</script>