我希望“s.value”全部变为小写,然后ucwords到它,但我不知道该怎么做,因为它在一个表单内。
基本上我想做这样的事情:ucwords(strtolower(s.value here));
这是表格:
<form role="search" method="get" id="searchform" action="http://chusmix.com/?s=" onsubmit="if (document.getElementById('s2').value.length > 5) window.location = action + '<php echo $city; ?>++++' + s.value; return false;" >
由于
答案 0 :(得分:20)
<script type="text/javascript">
function ucwords (str) {
return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
return $1.toUpperCase();
});
}
function strtolower (str) {
return (str+'').toLowerCase();
}
</script>
<form role="search" method="get" id="searchform" action="http://chusmix.com/?s=" onsubmit="if (document.getElementById('s2').value.length > 5) window.location = action + '<?php echo $city; ?>++++' + ucwords(strtolower(s.value)); return false;" >
javascript函数来自PHP.JS
答案 1 :(得分:3)
Javascript String有两个功能:toLowerCase()和toUpperCase,你可以将它们与
一起使用function toInitCap(input)
{
input = input || "";
return input.substring(0,1).toUpperCase() + input.substring(1,str.length).toLowerCase();
}
toInitCap(s.value)
答案 2 :(得分:2)
你可能像我一样想要在一行上做这件事,我用过:
"your strING".toLowerCase().replace(/(?:(^.{1})|\ [a-z]{1})/g, function(a){return a.toUpperCase();})
返回Your String
答案 3 :(得分:1)
+ <?php echo ucwords(strtolower($s_value)); ?>;
答案 4 :(得分:0)
你想这样做:
$out = ucwords(strtolower($_GET['s.value']));
如果s.value是您要传递的输入名称
答案 5 :(得分:0)
如果你想在文本框中编辑文本时这样做,那么我不确定你会做什么,但是如果你想让它小写,那么大写后他们提交表单然后就简单了。
ucwords(用strtolower($ _ GET [ 'formid']))
答案 6 :(得分:0)
str.length =&gt; input.length 强>
function toInitCap(input)
{
input = input || "";
return input.substring(0,1).toUpperCase() + input.substring(1,input.length).toLowerCase();
}
toInitCap(s.value)