怎样修改input的原型!?如下
<input type="text" ></input>怎样修改原型,加入 xx="xx" 或者是xx()
<input type="text" xx="1"></input>
或<input type="text" xx()></input>试过Input.prototype.xx=function(){alter("123")}这样不行我需要 当xx="1"的时候自己,自动执行一段函数,要在原型里面!用户只需要 写xx="1" xx="2" 就能执行相应函数!比如
xx="1" 就弹出1
<input type="text" ></input>怎样修改原型,加入 xx="xx" 或者是xx()
<input type="text" xx="1"></input>
或<input type="text" xx()></input>试过Input.prototype.xx=function(){alter("123")}这样不行我需要 当xx="1"的时候自己,自动执行一段函数,要在原型里面!用户只需要 写xx="1" xx="2" 就能执行相应函数!比如
xx="1" 就弹出1
<input type="text" id="txtInput" value="abc" newProperty="1"></input>
<input type="button" id="btnSet" value="Set newProperty to 2" />
<script type="text/javascript">
<!--
var oInput = document.getElementById("txtInput");
oInput.onpropertychange = function() {
if (this.newProperty
&& this.newProperty == "2")
{
alert("hello");
}
};
var oBtn = document.getElementById("btnSet");
oBtn.onclick = function() {
oInput.newProperty = "2";
};
//-->
</script>
</body>