gpt4 book ai didi

javascript - 如何在这个现实世界的示例中动态包含 javascript?

转载 作者:行者123 更新时间:2023-11-30 23:43:21 24 4
gpt4 key购买 nike

我在这里读到可以动态包含js http://www.phpied.com/javascript-include/

我想通过使用 http://www.softcomplex.com/products/tigra_slider_control/multiple_slider_designs_demo.html 将 tigra slider 示例(参见 http://accessify.com/tools-and-wizards/developer-tools/html-javascript-convertor/ )协调到动态代码中来尝试这个真实的示例将静态代码转换为动态代码:

<table>
<tr>
<td>
<div style="float: left;position:relative">
<div id="slider1" style="float: left">
<script language="JavaScript">
var A_TPL = {
'b_vertical': false,
'b_watch': true,
'n_controlWidth': 120,
'n_controlHeight': 16,
'n_sliderWidth': 16,
'n_sliderHeight': 15,
'n_pathLeft': 1,
'n_pathTop': 1,
'n_pathLength': 103,
's_imgControl': 'img/blueh_bg.gif',
's_imgSlider': 'img/blueh_sl.gif',
'n_zIndex': 1
}

var A_INIT1 = {
's_form': 0,
's_name': 'sliderValue1',
'n_minValue': 0,
'n_maxValue': 100,
'n_value': 20,
'n_step': 1
}
new slider(A_INIT1, A_TPL);
</script>
</div>

<div style="float: left">
<input name="sliderValue" id="sliderValue1" type="Text" size="3" >
</div>
</div>
</td>
</tr>

<tr>
<td>
<div style="float: left;position:relative">
<div style="float: left">
<script language="JavaScript">
var A_INIT2 = {
's_form': 0,
's_name': 'sliderValue2',
'n_minValue': -50,
'n_maxValue': 50,
'n_value': 0,
'n_step': 1
}
new slider(A_INIT2, A_TPL);
</script>
</div>
<div style="float: left">
<input name="sliderValue" id="sliderValue2" type="Text" size="3">
</div>
</div>
</td>
</tr>

<tr>
<td>
<div style="float: left;position:relative">
<div style="float: left">
<script language="JavaScript">
var A_INIT3 = {
's_form': 0,
's_name': 'sliderValue3',
'n_minValue': -100,
'n_maxValue': 0,
'n_value': -20,
'n_step': 1
}

new slider(A_INIT3, A_TPL);
</script>
</div>
<div style="float: left">
<input name="sliderValue" id="sliderValue3" type="Text" size="3">
</div>
</div>
</td>
</tr>
</table>

这将给出

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
</title>
<script language="JavaScript" src="slider.js"></script>
</head>
<body>
<form action="index.html" method="get" name="demoForm">
<script>
document.write("<table>");
document.write("<tr>");
document.write("<td>");
document.write("<div style=\"float: left;position:relative\">");
document.write("<div id=\"slider1\" style=\"float: left\">");
document.write("<script language=\"JavaScript\">");
document.write(" var A_TPL = {");
document.write(" 'b_vertical': false,");
document.write(" 'b_watch': true,");
document.write(" 'n_controlWidth': 120,");
document.write(" 'n_controlHeight': 16,");
document.write(" 'n_sliderWidth': 16,");
document.write(" 'n_sliderHeight': 15,");
document.write(" 'n_pathLeft': 1,");
document.write(" 'n_pathTop': 1,");
document.write(" 'n_pathLength': 103,");
document.write(" 's_imgControl': 'img\/blueh_bg.gif',");
document.write(" 's_imgSlider': 'img\/blueh_sl.gif',");
document.write(" 'n_zIndex': 1");
document.write(" }");
document.write("");
document.write(" var A_INIT1 = {");
document.write(" 's_form': 0,");
document.write(" 's_name': 'sliderValue1',");
document.write(" 'n_minValue': 0,");
document.write(" 'n_maxValue': 100,");
document.write(" 'n_value': 20,");
document.write(" 'n_step': 1");
document.write(" }");
document.write(" new slider(A_INIT1, A_TPL);");
document.write("<\/script>");
document.write("<\/div>");
document.write("");
document.write("<div style=\"float: left\">");
document.write("<input name=\"sliderValue\" id=\"sliderValue1\" type=\"Text\" size=\"3\" >");
document.write("<\/div>");
document.write("<\/div>");
document.write("<\/td>");
document.write("<\/tr>");
document.write("");
document.write("<tr>");
document.write("<td>");
document.write("<div style=\"float: left;position:relative\">");
document.write("<div style=\"float: left\">");
document.write("<script language=\"JavaScript\">");
document.write(" var A_INIT2 = {");
document.write(" 's_form': 0,");
document.write(" 's_name': 'sliderValue2',");
document.write(" 'n_minValue': -50,");
document.write(" 'n_maxValue': 50,");
document.write(" 'n_value': 0,");
document.write(" 'n_step': 1");
document.write(" }");
document.write(" new slider(A_INIT2, A_TPL);");
document.write("<\/script>");
document.write("<\/div>");
document.write("<div style=\"float: left\">");
document.write("<input name=\"sliderValue\" id=\"sliderValue2\" type=\"Text\" size=\"3\">");
document.write("<\/div>");
document.write("<\/div>");
document.write("<\/td>");
document.write("<\/tr>");
document.write("");
document.write("<tr>");
document.write("<td>");
document.write("<div style=\"float: left;position:relative\">");
document.write("<div style=\"float: left\">");
document.write("<script language=\"JavaScript\">");
document.write(" var A_INIT3 = {");
document.write(" 's_form': 0,");
document.write(" 's_name': 'sliderValue3',");
document.write(" 'n_minValue': -100,");
document.write(" 'n_maxValue': 0,");
document.write(" 'n_value': -20,");
document.write(" 'n_step': 1");
document.write(" }");
document.write("");
document.write(" new slider(A_INIT3, A_TPL);");
document.write("<\/script>");
document.write("<\/div>");
document.write("<div style=\"float: left\">");
document.write("<input name=\"sliderValue\" id=\"sliderValue3\" type=\"Text\" size=\"3\">");
document.write("<\/div>");
document.write("<\/div>");
document.write("<\/td>");
document.write("<\/tr>");
document.write("<\/table>");
document.write("");
</script>

<input name="Submit" type="Submit" value="Submit">

</form>

</body>
</html>

但运行文档时只有字段不出现 slider 。为什么?

最佳答案

如果您需要动态添加脚本到页面,可以通过注入(inject) <script src="..."></script> 来实现。标记为<head> 。正如您所见,将脚本内容直接注入(inject)页面是有问题的。

关于javascript - 如何在这个现实世界的示例中动态包含 javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3923688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com