我正在尝试制作一个显示雅虎图的嵌入代码的文件
embeded脚本是
<embed bgcolor="#dbdbd3" flashvars="lcId=1169793726234&state=symbol%3D^nsebank;range=1d;indicator=ema(13,34,55)+macd+rsi+stochasticfast;charttype=candlestick;crosshair=on;ohlcvalues=0;logscale=on;source=undefined" loop="false" menu="false" name="BANKNIFTY" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://us.js2.yimg.com/us.yimg.com/i/us/fi/yfc/swf/flashchart_1.18.swf" style="height: 775px; width: 550px" type="application/x-shockwave-flash" wmode="opaque"></embed>
在这个脚本中,我希望从下拉菜单列表中获取state = symbol = ^ nsebank(^ nsebank)的值,然后单击“计算”按钮时显示嵌入代码
我编写的代码如下 -
<div id="looknorth"></div>
<script type="text/javascript">
function ln(){
D11=parseFloat(D1.value);
document.getElementById('looknorth').innerHTML='<embed bgcolor="#dbdbd3" flashvars="lcId=1169793726234&state=symbol%3D"+D11+";range=1d;indicator=ema(13,34,55)+macd+rsi+stochasticfast;charttype=candlestick;crosshair=on;ohlcvalues=0;logscale=on;source=undefined" loop="false" menu="false" name="BANKNIFTY" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://us.js2.yimg.com/us.yimg.com/i/us/fi/yfc/swf/flashchart_1.18.swf" style="height: 775px; width: 550px" type="application/x-shockwave-flash" wmode="opaque"></embed>';} </script>
<table border=1 cellpadding=2 cellspacing=1 width="400">
<tr>
<td style="background-color:#123742; font-size:12 ; font-weight:bold">
<font color="#FFFFFF">Compounding</font>
<td> <br />
<select name="D1">
<option value="^nsei">Annually</option>
<option value="^bsen">Half Yearly</option>
</select>
<tr>
<td colspan="2" ALIGN="center">
<input type=button style="background-color:#123742; color:#FFFFFF; font-weight:bold; font-size:15" name=calculate value=Calculate onClick=ln();>
</table>
脚本无效,请帮我解决错误。
答案 0 :(得分:0)
<div id="looknorth"></div>
<script type="text/javascript">
function ln(){
D1 = document.getElementsByName("D1")[0]
D11=parseFloat(D1.value);
document.getElementById('looknorth').innerHTML='<embed bgcolor="#dbdbd3" flashvars="lcId=1169793726234&state=symbol%3D'+D11+';range=1d;indicator=ema(13,34,55)+macd+rsi+stochasticfast;charttype=candlestick;crosshair=on;ohlcvalues=0;logscale=on;source=undefined" loop="false" menu="false" name="BANKNIFTY" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://us.js2.yimg.com/us.yimg.com/i/us/fi/yfc/swf/flashchart_1.18.swf" style="height: 775px; width: 550px" type="application/x-shockwave-flash" wmode="opaque"></embed>';
}
</script>
<table border=1 cellpadding=2 cellspacing=1 width="400">
<tr>
<td style="background-color:#123742; font-size:12 ; font-weight:bold">
<font color="#FFFFFF">Compounding</font>
<td> <br />
<select name="D1">
<option value="^nsei">Annually</option>
<option value="^bsen">Half Yearly</option>
</select>
<tr>
<td colspan="2" ALIGN="center">
<input type=button style="background-color:#123742; color:#FFFFFF; font-weight:bold; font-size:15" name="calculate" value="Calculate" onClick='ln()'>
你在innerHTML行周围有一些不匹配的引号。同样,你从未定义过你的javascript中的D1,所以当你要求D1.value时,它不知道你想要什么。
答案 1 :(得分:0)
tfw.debugger:
state=symbol%3D'+D11+';range=1d;…
就是您所拥有的。
state=symbol=^nsei;…
看起来非常错误。您可能想检查这些变量。使用网络浏览器的console.log(字符串)控制台/调试器功能在有疑问时测试对象和变量(F12在大多数浏览器中显示控制台/开发工具)
<div id="looknorth"></div>
<script language='javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type="text/javascript">
function ln(){
//var D11=String($('select[name=D1]').val());
var D11=String(D1.value),
text = '<embed bgcolor="#dbdbd3" flashvars="lcId=1169793726234&state=symbol%3D'+D11+';range=1d;indicator=ema(13,34,55)+macd+rsi+stochasticfast;charttype=candlestick;crosshair=on;ohlcvalues=0;logscale=on;source=undefined" loop="false" menu="false" name="BANKNIFTY" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://us.js2.yimg.com/us.yimg.com/i/us/fi/yfc/swf/flashchart_1.18.swf" style="height: 775px; width: 550px" type="application/x-shockwave-flash" wmode="opaque"></embed>';
//try { console.log(D11); } catch(err) { window.alert(String(D11)); }
//$('div#looknorth').html(text);
document.getElementById('looknorth').innerHTML=text;
}
</script>
<table border=1 cellpadding=2 cellspacing=1 width="400">
<tr>
<td style="background-color:#123742; font-size:12 ; font-weight:bold">
<font color="#FFFFFF">Compounding</font>
<td> <br />
<select name="D1" id="D1">
<option value="^nsei">Annually</option>
<option value="^bsen">Half Yearly</option>
</select>
<tr>
<td colspan="2" ALIGN="center">
<input type=button style="background-color:#123742; color:#FFFFFF; font-weight:bold; font-size:15" name=calculate value=Calculate onClick=ln();>
</table>
)
答案 2 :(得分:0)
您的代码中存在一些问题:
用这个替换JS函数:
function ln(){
var D1 = document.getElementsByTagName("D1")[0];
var D11 = D1.value;
var lknorth = document.getElementById('looknorth');
lknorth.innerHTML= '<embed bgcolor="#dbdbd3" flashvars="lcId=1169793726234&state=symbol%3D' + D11 + ';range=1d;indicator=ema(13,34,55)+macd+rsi+stochasticfast;charttype=candlestick;crosshair=on;ohlcvalues=0;logscale=on;source=undefined" loop="false" menu="false" name="BANKNIFTY" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://us.js2.yimg.com/us.yimg.com/i/us/fi/yfc/swf/flashchart_1.18.swf" style="height: 775px; width: 550px" type="application/x-shockwave-flash" wmode="opaque"></embed>';
}