HTML输入需要包含特定的文本
html <input needs to contain specific text
我有一个输入字段和一个按钮。现在我想让它只接受包含我选择的单词的文本。
<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/4SFUbhiPform.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,则显示错误,否则将提交链接。谢谢!
相关文章:
- 无法将包含文本和图像的SVG保存到画布
- 存储包含html标记的文本
- Firefox插件:保存到文本文件的HTTP日志,其中包含时间、用户名、计算机名;t创建文本文件
- 如果Div包含精确文本,则添加类
- 检查选择器在jQuery中是否包含文本(即不是媒体)
- 使用 jQuery 检查文本可见性 .包含代码的行为不符合预期
- jQuery 隐藏按钮,如果它们不包含文本
- 当文本框中包含数据时禁用按钮
- 过滤包含一些文本的 PHP 数据表
- 创建包含文本内容的新 Google 云端硬盘文件 (javascript)
- 使用 javascript 检查元素是否包含子标记而不是文本
- 如果单元格中的文本包含特定单词,则在其中放入图像
- 选择框文本等于而不是选择框文本包含-jQuery
- JavaScript-当整个文本包含时替换
- 如果文本包含“@”,请更改“@”的颜色
- 替换链接和文本,如果文本包含:
- Magento翻译的文本包含在Javascript文件
- jQuery slideDown()在文本包含<和>时不工作
- 按属性值和文本包含隐藏元素
- 如何使用正则表达式匹配不包含特定子字符串的字符串?