html传值后的变量在html里面怎么获取使用?

html传值后的变量在html里面怎么获取使用?,第1张

你得自己写个函数即可
<script>
var yugi = function(key){
    var sear = locationsearch;
    var reg = new RegExp("" + key + "=((:(!(&|\b))))", "g");
    return searreplace(reg, "$1");
}
</script>
-------------
<td><script>documentwrite(yugi("aa"));</script></td>
<td><script>documentwrite(yugi("bb"));</script></td>

href后边的属性是一个字符串,格式化为字符串不就可以了?
如:windowlocationhref=""+text+"html";
也就是说,text变量的内容是a时,则会打开ahtml,当然,如果你的变量中存在的就是类似于text = "ahtml";的话,更好办了
locationhref = text就可以了!

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Demo</title>
  </head>
  
  <body>
    <video id="video" src="abcmp4" controls preload></video>
    <script>
var a = windowscreenwidth;
var b = windowscreenavailHeight;
var obj = documentgetElementById("video");
objstylewidth=a+"px";
objstyleheight=b+"px";
    </script>
  </body>
</html>

通过js代码可以实现对标签进行 *** 作,比如设置和修改css属性等。

但是为了方便,一般会给标签设置一个独一无二的id。

prompt只是d出一个对话框

<html>
    <head>
        <script type="text/javascript">
            function disp_prompt() {
                var name = prompt("请输入您的名字", "Bill Gates") if (name != null && name != "") {
                    documentwrite("你好," + name + "!今天过得好吗?")
                }
            }
        </script>
    </head>
    
    <body>
        <input type="button" onclick="disp_prompt()" value="显示一个提示框" />
    </body>
</html>

1、先新建一个html文件,命名为testhtml。

2、在testhtml文件内,使用div标签创建一个模块,并设置其id为outinput,主要用于下面通过该id获得div对象。

3、在js标签内,定义一个数组arr,数组内定义三个元素,分别为“测试一”,“测试二”,“测试三”。

4、在js标签内,通过length属性获得数组arr的长度,即元素的个数,主要用于for语句中限制循环的次数。

5、在js标签内,定义一个变量html,使用for循环遍历arr数组,每次读取数组元素,将元素值与p标签组合,用于实现在页面出来。

6、在js标签内,使用getElementById()方法通过id(outinput)获得div对象,通过innerHMTL属性将html变量输出在页面div标签中,从而实现取出数组值并显示出来。

7、最后在浏览器打开testhtml文件,查看实现的效果,就完成了。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/13376603.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-24
下一篇 2023-07-24

发表评论

登录后才能评论

评论列表(0条)

保存