美文网首页
js:input相关属性问题解答

js:input相关属性问题解答

作者: 十月木樨 | 来源:发表于2019-02-21 21:11 被阅读0次

1,input监听事件

input不断输入时,事件随时关注value的变化,并产生相应的结果。

oninput='v()' onchange='v()' 

<html>

<head>

<script type="text/javascript">

    function upperCase(x)

    {

        var y=document.getElementById(x).value

        alert(y);

        document.getElementById(x).value=y.toUpperCase()

    }

</script>

</head>

<body>

    Enter your name: <input type="text" id="fname" onchange="upperCase(this.id)">

</body>

</html>

input复选框被选中状态:inputs[i].checked

2,innerHTML代表标签内容,value代表标签的value值,一般用于改变input输入框中的值

document.getElementById("show").innerHTML = str1;

document.getElementById('lname').value = str2;

3,解决html中刷新页面后checkbox还选中的问题 

autocomplete="off"

<input class="che" name="che" type="checkbox" autocomplete="off"  value="HTTP" />HTTP

4,控制在input的text里输入的值只能是数字。

<input type='text' onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" onblur="this.v();" />

5,input-placeholder获取焦点清空:

html中,placeholder作为input的一个属性,起到了在输入框中占位并提示的作用。

但是有一些浏览器,如chrome,当鼠标点击输入框时,placeholder的值不消失,只有输入数据才消失,会使前端用户体验大打折扣。

html代码:

<input type="text" placeholder="请输入">

在其中只需加入两个简短的js即可:

<input type="text" placeholder="请输入" onfocus="this.placeholder=''" onblur="this.placeholder='请输入'"></input>

6,input的file组件按钮上默认文字的修改:

https://blog.csdn.net/skfzc/article/details/48341249

相关文章

网友评论

      本文标题:js:input相关属性问题解答

      本文链接:https://www.haomeiwen.com/subject/hsxjyqtx.html