我試圖在包裹在錨點中的div中輸出我的值。基本上,有人打出了他想要的高度,並且給了他等同的數據表。如何在包含錨點的div中輸出我的值javascript
我不能解決如何輸出我想在包裹在一個錨點div的字符串的方式。
這裏是我的代碼:
<form name="test">
<label for="height">Height</label>
<input type="text" name="height" /><br>
<label for="width">Width</label>
<input type="text" name="width" /><br>
<label for="depth">Depth</label>
<input type="text" name="depth" /><br>
<label for="load">Load</label>
<input type="text" name="load" /><br>
<input type="button" onclick="calculate();" value="Calculate" /><br><br>
</form>
<div id="result">
</div>
<script type="text/javascript">
function calculate()
{
var height = document.test.height.value;
if (height <= 525) {
var str = "Download your Datasheet 1";
}
else if (height < 645) {
var str = "Datasheet 2";
}
else if (height > 1265) {
var str = "This configuration is beyond the standard range of top-load testers. Please contact Mecmesin Sales to discuss ways to meet your requirements.";
}
else if (isNaN(height)) {
window.alert(height + ' is not a number!');
}
else {
var str = "Datasheet 3";
}
document.test.result.value = str.anchor();
}
</script>
在此先感謝。
是的,但我可以做到這一點,我可以嗎? var str ='Download your Datasheet 1'; – Codeninja 2013-03-21 16:06:40
你可以,但建議習慣直接處理dom。這更有趣,尤其是當你使用像Dojo這樣的框架時...... – Radiotrib 2013-03-21 16:09:04
哇!真的很有趣我不得不說...感謝百萬... – Codeninja 2013-03-21 16:13:33