大概有这么3种做法,你参考一下吧。用得较多的是第二和第三种
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tilte</title>
</head>
<style type="text/css">
input {
margin: 0;
padding: 0;
}
li {
line-height: 2em;
}
#vor {
border-right: none;
width: 70px;
}
#nach {
border-left: none;
margin-left: -8px;
}
#back {
border: none;
border-bottom: 1px dashed black;
}
</style>
<body>
<ol>
<li>两个文本框
<input type="text" id="vor" value="ChinaNet-" readonly="readonly" />
<input type="text" id="nach" />
</li>
<li>文本+文本框
<ul>
<li>普通
<span>ChinaNet-</span>
<input type="text"/>
</li>
<li>美化
<span>ChinaNet-</span>
<input type="text" id="back" />
</li>
</ul>
</li>
<li>一个文本框+javascript
<input type="text" id="js-control" value="ChinaNet-"/>
</li>
</ol>
</body>
<script type="text/javascript">
var textField = documentgetElementById('js-control'), //获取表单域
startText = textFieldvalue; //获取开头字符串
textFieldonkeyup = function(){
//如果不是以startText开头的,就把文本框内的值设为startText
(textFieldvalueindexOf(startText)===0) || (textFieldvalue = startText);
};
</script>
</html>
<script type="text/javascript">// text/javascript 写错了,掉了一个i
function bj()
{
var x=documentgetElementsByTagName("form")[0];
if(xtextfieldvalue!="8888")
{
alert("误");
windoweventreturnValue=false; //把这个放到最后。现在的代码会d出“误”,
//而不 会d出“不会d出对话框”
alert("不会d出对话框");
}
}
</script>
<body><form name="form1" method="post" action="">
<p><input type="submit" name="Submit" value="提交" onclick="bj()">
<input type="text" name="textfield"> </p>
</form></body>
1、jsd出文件选择框:
给按钮定义以下javascript函数:
var inputObj=documentcreateElement('input')inputObjsetAttribute('id','_ef');
inputObjsetAttribute('type','file');
inputObjsetAttribute("style",'visibility:hidden');
documentbodyappendChild(inputObj);
inputObjclick();
inputObjvalue ;
单击已经添加函数的按钮会d出选择本地文件的对话框。
2、写一个隐藏域, 当用户选择文件之后把的路径赋给这个隐藏域, 然后在action中就可以获取到文件的路径了,代码如下:
function showRealPath(filePath){documentgetElementsByName("textfield")[0]value = filePath;
}
<input type="file" name="uploadfile" onfocus="showRealPath(thisvalue);"/>
<input type="hidden" name="uploadfileRealPath">
以上就是关于JavaScript 如何使得文本框Text中的前几位不能修改或删除呢全部的内容,包括:JavaScript 如何使得文本框Text中的前几位不能修改或删除呢、js中的getElementsByTagName、JavaScript如何d出文件选择框,然后返回文件完整路径等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)