如何从输入中删除双引号

How to remove doublequotes from input

本文关键字:删除 输入      更新时间:2023-09-26

所以我正在为一个网站的输入工作,这将生成一个div标签及其适当的子元素,需要为网站完成其功能。所以我的终极问题如下:

<!DOCTYPE html>
<html>
<head id="head">
    <title>Question Recall</title>
    <script src="javascripts/jquery.js"></script>
</head>
<body id="body">
    <p>Input File Path: </p><input type="text" id="filepath" value='"C:'Users'Christopher'Desktop'recall.js"'>
    <input type="button" onclick="startgame()" value="Ok">
    <input type="button" onclick="update()" value="Update">
    <p id="quiztitle"></p>
</body>
<script>
    $('#filepath').splice
    function startgame() {
        var filesrc = document.getElementById("filepath").value;
        var gamefile = document.createElement('script');
        gamefile.setAttribute('src', filesrc);
        document.head.appendChild(gamefile);
    };
    function update() {
        $(".question").remove();
        for (var qgs=1; qgs <= tq; qgs++) {
            $("body").append('<div id="q' + (qgs) + '" class="question"><h2 class="questionnum">Question ' + (qgs) + '</h2><br /><p class="question' + (qgs) + '"></p></div>');
        };
    };
</script>
</html>

问题~ ~ ~ ~当试图使用type="file"属性上传召回文件发生并得到文件未找到的错误时,我坚持使用type="text"属性。这些就是我的问题的来源。

A)由于javascript没有访问文件系统的权限,是否有一种方法,我可以有"文件"属性,它仍然通过验证作为一个适当的脚本src="?

B)是否有一种方法可以通过拼接或禁用关键字来自动删除输入框末尾和开头的双引号("),或者即使你知道这样做的更好的功能。请记住,这将是一个粘贴字段。

另外,body之后的脚本标签将被移动到一个专门的文件中,但为了方便显示和编辑,我只是在html文档中制作了javascript

$('#filepath').on('input',function(){
   $(this).val( $(this).val().replace(/"/g,'') );
});

你可以使用on输入和使用regex删除所有的"在你的输入和放回字符串