以修改width为例
<script>
//首先获取到图片的id,也就是在javascript中获取大img,方便后续 *** 作
var face = document.getElementById("face")
//通过face的style属性修改,这里图片的宽度就会变为500px
face.style.width = "500px"</script>
如果你是想在页面输入数值,图片就会变化的话,需要在页面添加输入框和按钮
<input type="text" id="widthValue">
<button id="btn">确定</button>
<script>
//首先获取按钮和输入框的数值
var face = document.getElementById("face")
var widthValue = +document.getElementById("widthValue").value
var btn = document.getElementById("btn")
//通过点击调用匿名函数,给图片赋予新的宽度
btn.onclick = function(){
face.style.width = widthValue
}
</script>
实现html页面的参数传递
方法一:
下面是javascrīpt的一种实现方法, 这个函数是通过window.location.href中的分割符获得各个参数。
有了这个函数,就可以在页面之间传递参数了。
方法二:
html地址传递参数进行其他事情.
方法三:
方法四:
做中英转换的时候,要准确的获取参数并取出,所以做了一个简单的html中用js获取当取地址栏的一个Object。
里面有三个方法:
1、request.QueryString("参数")//获取指定参数,返回字符串
2、request.QueryStrings()//获取全部参数,并返回数组
3、request.setQuery("参数","参数的值")//如果当前地址栏有此参数,那么将更新此参数,否则返回一个新的地址栏参数字符串。
例如:
当前地址栏参数字符串为:?name=a&site=never_online
alert(request.setQuery("name","blueDestiny"))
如果地址栏参数中有"name",那么返回?name=blueDestiny&site=never_online
setQuery方法有自动追加参数的功能。如:
当前地址栏参数字符串为:?site=never_online
alert(request.setQuery("name","blueDestiny"))
则返回?site=never_online&name=blueDestiny
同理,如果地址栏没有参数,也会自动追加参数
alert(request.setQuery("name","blueDestiny"))
返回?name=blueDestiny
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)