插件程序:jQuery在此插件中不起作用

时间:2014-12-28 作者:lost_in_magento

我一直在写一个插件,但想给插件添加一些功能

在此程序中,JQuery不起作用,请帮助我

我的要求是

检查此URL:codelisense.com/wp/about

1、当我单击下拉列表或按钮“是”时,文本区域不会显示

我的意思是我不知道为什么jquery没有出现在这个插件中

2、请在附件中指导我

<?php

//Creating tables
function sukkyservices_installation(){
 global $wpdb;

 $table_name = $wpdb->prefix. "sukkyservices_contact";

 if($wpdb->get_var("SHOW TABLES LIKE \'$table_name\'" ) != $table_name){
$sql= "CREATE TABLE $table_name (
       id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
       firstname VARCHAR(30) NOT NULL,
       lastname VARCHAR(30) NOT NULL,
       email VARCHAR(50),
       query VARCHAR(255),
       reg_date TIMESTAMP

       );";
require_once (ABSPATH. \'wp-admin/includes/upgrade.php\' );
dbDelta($sql);
}
}
register_activation_hook(__FILE__, \'sukkyservices_installation\');

function sukkyservices_shortcode(){
?>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<style>
</style>
<div class="wrap">

 <?php

if(isset($_POST["Submit"])){

$firstname=$_POST[firstNametxt];
$lastname=$_POST["lastNametxt"];
$phoneno=$_POST["phoneno"];
$email=$_POST["email"];
$appplat=$_POST["appplat"];
$conditions=$_POST["conditions"];
$apptype=$_POST["apptype"];
$equity=$_POST["equity"];
$message= $firstname.$lastname.$phoneno.$email.$appplat.$conditions.$apptype.$equity;


$headers[] = \'From: Me Myself <[email protected]>\';
$to= \'[email protected]\';
$subject=\'hie\';
$message= $firstname.$lastname.$phoneno.$email.$appplat.$conditions.$apptype.$equity;

wp_mail( $to, $subject, $message, $headers );


}

?>


<!DOCTYPE html>
<html>
 <form action="" method="post" enctype="multipart/form-data" >
 <h3><label style=" text-align: center; width: 100%;">Enquiry Form</label></h3>   
  <h4><label for="first-name-text">First name: </label></h4><input type="text" id="first-name-text" name="firstNametxt" class="form-control floating-label" placeholder="First Name" /><br/>
  <h4><label for="last-name-text">Last name: </label></h4><input type="text" id="last-name-text" name="lastNametxt" class="form-control floating-label" placeholder="Last Name" /><br/>
  <h4><label for="email">Email: </label></h4><input type="email" id="email" name="email" class="form-control floating-label" placeholder="e-mail" /><br/>
  <h4><label for="phoneno">Phone number: </label></h4><input type="text" id="phoneno" name="phoneno" class="form-control floating-label" placeholder="Phone number"> <br/>
  <h4><label for="appplat">App Platform </label></h4><select name="appplat">
<option value="Android">Android</option>
<option value="PHP">PHP</option>
<option value=".NET">.NET</option>
<option value=".NET">Java</option>
</select>
<h4><label for="NDA">Required NDA to be signed </label></h4><input name="Submit" type="button" value="Yes" class="btn btn-primary btn-raised mdi-action-grade" id="Yes" >
<input name="Submit" type="button" value="No" class="btn btn-primary btn-raised mdi-action-grade" id="No" >
 <select id="conditions" name="conditions">
<option class="yes" value="yes" selected="selected">Yes</option>
<option class="no" value="no"> No </option>
</select><br/>
<h4><label for="apptype" class="specify" style="display: block;">App type </label></h4>
<select name="apptype" class="apptype">  
 <option value="games">Games</option>
 <option value="Business">Business</option>
 <option value="Utilites">Utilities</option> 
 <option value="Others">Others</option>
</select><br/>
<textarea class="specify" name="specify" style="display: none;" >Give us the brief gist of your idea</textarea> <br/>
<h4><label for="equity" class="equity" style="display: block;">Percentage of Equity you would like to give </label></h4><br/>
<select name="equity" class="equity"> 
<?php
for($i=5; $i<=100; $i+=5){
echo "<option value=".$i."> ".$i."</option>";
}
?>
</select> <br/>
<br/>
<h4><label for="upload" class="upload" >Upload supporting documents</label></h4><br/>
<input type="file" id="upload" name="upload" class="form-control floating-label" placeholder="Upload supporting documents" /><br/>
   <input name="Submit" type="submit" value="Submit" class="btn btn-primary btn-raised mdi-action-grade" id="submit" >
    <input name="Cancel" type="submit" class="btn btn-default btn-raised mdi-action-grade" value="Cancel" id="cancel" style="margin-left: 15px" >
</form>
</div>
</html>
<?php

}

add_shortcode( \'SSS\', \'sukkyservices_shortcode\' ); 

function sukkyservices_js() {
wp_register_script(\'sukkyservices_jscall\', plugins_url(\'/js/sukkyservices_js.js\', __FILE__), array(\'jquery\'),\'1.1\', true);
wp_enqueue_script(\'sukkyservices_jscall\');
}

add_action( \'wp_enqueue_scripts\', \'sukkyservices_js\' );  
?>
Jquery sukkyservices\\u js。js文件

$j=jQuery.noConflict();
$j(document).ready(function(){
  $j("#Yes").click(function(){
    $j(".apptype").show();
    $j(".specify").hide();
  });
  $j("#No").click(function(){
    $j(".specify").show();
    $j(".apptype").hide();
  });
});

1 个回复
SO网友:Sam Holguin

首先,我建议像这样包装您的JS:

(function ($) {

    $(document).ready(function(){
        $("#Yes").click(function(){
            $(".apptype").show();
            $(".specify").hide();
        });
        $("#No").click(function(){
            $(".specify").show();
            $(".apptype").hide();
        });
    });

})(jQuery);
您还将jQuery排队两次,上面的脚本排队两次。。。。使用您的短代码,您不需要声明DOCTYPE,也不需要将from包装在HTML标记中。

我还将在文档的头部包含引导CSS文件。

结束