HTML输入需要包含特定的文本

html <input needs to contain specific text

本文关键字:文本 包含特 输入 HTML      更新时间:2023-09-26

我有一个输入字段和一个按钮。现在我想让它只接受包含我选择的单词的文本。

    <input type="hidden" name="post_id" id="fep-post-id" value="<?php echo $post_id ?>">
    <button type="button" id="fep-submit-post" class="active-btn">Go</button><img class="fep-loading-img" src="<?php echo plugins_url( 'static/img/ajax-loading.gif', dirname(__FILE__) ); ?>"/>

这是一个提交表单,人们只能提交来自特定网站的url。它是一个Wordpress插件内的php文件

我尝试了脚本解决方案,但我认为它与插件scripts.js混淆了。我假设我需要在代码片段中添加一些代码:

$("#fep-submit-post.active-btn").on('click', function() {
        tinyMCE.triggerSave();
        var title           = $("#fep-post-title").val();
        var content         = $("#fep-post-content").val();
        var bio             = $("#fep-about").val();
        var category        = $("#fep-category").val();
        var tags            = $("#fep-tags").val();
        var pid             = $("#fep-post-id").val();
        var fimg            = $("#fep-featured-image-id").val();
        var nonce           = $("#fepnonce").val();
        var message_box     = $('#fep-message');
        var form_container  = $('#fep-new-post');
        var submit_btn      = $('#fep-submit-post');
        var load_img        = $("img.fep-loading-img");
        var submission_form = $('#fep-submission-form');
        var post_id_input   = $("#fep-post-id");
        var errors          = post_has_errors(title, content, bio, category, tags, fimg);
        if( errors ){
            if( form_container.offset().top < $(window).scrollTop() ){
            $('html, body').animate({ scrollTop: form_container.offset().top-10 }, 'slow'); }
            message_box.removeClass('success').addClass('warning').html('').show().append(errors);
            return;
        }

这是我使用的两个文件:

scripts.js

http://pastebin.com/4SFUbhiP

form.php

之间的 ===>>>>> 和& lt; & lt; & lt; & lt; = = = = = =是我需要的输入字段验证。下面是提交按钮。http://pastebin.com/G53HScu3

我会这么做

<form onsubmit="return validator()">
    <input type="hidden" name="post_id" id="fep-post-id" value="<?php echo $post_id ?>">
    <button type="button" id="fep-submit-post" class="active-btn">Go</button><img class="fep-loading-img" src="<?php echo plugins_url( 'static/img/ajax-loading.gif', dirname(__FILE__) ); ?>"/>
</form>
<script type="text/javascript">
    var validator = function(){
        switch (variable) {
            case "allowed":
                submit form;
                break;
            default:
                return false;
        }
     }
</script>

在onsubmit属性中返回false将阻止表单提交。我只是给出了一个基本的例子,使用"允许",但您可能必须使用字符串函数来确定基本URL是否是您信任的网站之一。

可能有更好的方法来做到这一点-也许使用select -但稍加修改,这应该达到您的目标。

完成!:-)我已经将这段代码添加到scripts.js

if (title.toLowerCase().indexOf('collection') == -1)Error_string += ' allen ....
';

如果title/url不包含collection,则显示错误,否则将提交链接。谢谢!