Javascript 在一个“a”之后脱掉衣服&引用;从输入值

Javascript 在一个“a”之后脱掉衣服&引用;从输入值,javascript,strip,Javascript,Strip,我有一个脚本,它正在更改输入字段的值 我想要的输出是:A-Z(A和B结束,依此类推) 我怎样才能做到在“.”被剥夺之后的一切 <script language="JavaScript"> function hoofdlettermetpunt(obj) { var firstChar = document.all(obj).value.charAt(0); firstChar = firstChar.toUpperCase() + "

我有一个脚本,它正在更改输入字段的值

我想要的输出是:A-Z(A和B结束,依此类推)

我怎样才能做到在“.”被剥夺之后的一切

<script language="JavaScript">

    function hoofdlettermetpunt(obj)
    {
        var firstChar = document.all(obj).value.charAt(0);
        firstChar = firstChar.toUpperCase() + ".";
        document.all(obj).value = document.all(obj).value.replace(
                                  document.all(obj).value.charAt(0), firstChar);
    }

</script>

功能hoofdlettermetpunt(obj)
{
var firstChar=document.all(obj.value.charAt)(0);
firstChar=firstChar.toUpperCase()+“;
document.all(obj).value=document.all(obj).value.replace(
document.all(obj.value.charAt(0),firstChar);
}

我不懂Javascript,但您确实希望返回字符串开头的所有内容的子字符串,但不包括子字符串索引处的字符

return s.subString(indexOf('.')) // You may need to add a -1 to offset the location of the substring. 

要从字符串中删除点
后的任何内容,可以使用以下命令:

var str = 'My test. string';
var newstr = str.split('.',2)[0];

/// newstr will contain 'My test'
但是,我不确定您试图用代码做什么来实际回答您的示例问题。基本上,
.split
将始终返回一个数组,因此您可以直接使用
[0]
作为数组访问-这将为您提供数组中找到的第一个元素(由于拆分,它将是您想要的子字符串)。即使字符串不包含
,上述操作也会起作用

有关
.split()
的信息,请参阅以下内容:

我怎样才能做到“被剥夺”之后的一切

尝试:


一些示例输入字符串将很有用,例如在输入字段中键入内容的示例中。@pimvdb Ohh错误地,我在错误的部分给出了答案。。。我以为它是用java标记的。。。对不起
但我认为这仍然有效。
String str = "Hello.Whose this !!!";

String[] tempArr = str.split("\\.");

String finalVal = tempArr[0];       // Hello is obtained