繁体   English   中英

如何将4个字符串值从HTML页面传递到javascript文件?

[英]How pass 4 string values from HTML page to a javascript file?

希望将HTML页面中的4个字符串值(非用户输入)传递到单独文件中的javascript函数。

有一些javascript代码,图像翻转。 我在许多HTML页面上都使用过它,但它确实有效。

现在我希望将此代码放在一个名为“image-flip-comment.js”的单独文件中,每个网页都会传递4个字符串值。 该脚本将执行将在HTML页面中显示的功能。

这是工作代码的一部分,它来自我的HTML页面上的脚本。

<script language="JavaScript" type="text/javascript">
<!-- hide from non-JavaScript Browsers
Image_top1= new Image(100,100)
Image_top1.src = "../buttons/Rm_btn_fwa.gif"
//----more stuff ----

function SwapOutTop() {
document.imagebacktop.src = Image_top1.src; return true;
}
// - stop hiding -->
</script>


// here is PART of my code from the file  "image-flip-comment.js"

// Imageflip Javascript routine, version w passed values shown as comments
// <!-- hide from non-JavaScript Browsers  I'm going to assume this is 
obsolete?  

Image_top1= new Image(100,100)
Image_top1.src = "../buttons/${button_forw_a}!"
// Rm_btn_fwa.gif this went on above line

// more stuff for the other 3 parameters
function FwSwapBackTop() {
document.imagefliptop.src = Image_top1.src; return true;
}

那么你可以有一个参数化的功能

function imageflip(var your_parameter_name) {
...
...<!-- access the string here -->
...
}

并且根据您希望图像翻转的事件,通过onclick传递调用该​​函数

例如:

<a onclick="imageflip('some_string_value')" >click</a>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM