如何存储jquery点击功能并在其他页面上使用它 [英] How to store jquery click function and use it on other page

查看:69
本文介绍了如何存储jquery点击功能并在其他页面上使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了这个jquery函数



$('#btnMoreEnquiriesSELink')。click(function(){

$ .colorbox。 close();

setTimeout(function(){window.location.href =enquiry.php;},500);

$(#h2) .attr(选中,选中);

});



点击btnMoreEnquiriesSELink时,应该进行查询。用于SELink的php页面和Checkbox将自动打勾。



我如何实现?jquery在project.html页面,而enink.php中的SELink Checkbox代码。代码由其他人和上次所有代码在一个页面中生成。



更新尝试解决方案



 <   script     type   =  text / javascript    src   =  js / checkbox.js >  <   / script  >   - 我把它放在两页(项目和查询)


Checkbox.js代码
< script >
function callEnquiry(){
$ .colorbox.close();
setTimeout(function(){window.location.href =enquiry.php;},500);
$(#h2)。attr(checked,checked);
}
< / script >

项目页码Code

< div class = btnMPPopUpLeft > & nbsp; < / div > < div class = btnMPPopUpRight >
< a href = id = btnMoreEnquiriesAPLink > < div class = btnMoreEnquiries > 更多查询< / div > < / a > < / div >



< script type = text / javascript >
$( '#btnMoreEnquiriesSELink')点击(callEnquiry)。
< / script >





查询代码

 <   div     class   = 复选框 >  
< 输入 type = 复选框 名称 = type [] value = content-text id = h2 class = 复选框

<?php

for($ i = 0; $ i< count(@ $ _ POST [type]); $ i ++)

{

$ jyef = $ _ POST [ type] [$ i];

if($ jyef = = 'content-text') {

echo CHECKED;

} else {

echo ;

}

}

>
/>
< label < span class =code-attribute> for = h2 class = checkboxLabel > content-text < / label >
< / div > < br class = clear >





P / s:我尝试改变attr(check,true);但仍然没有工作

解决方案

('#btnMoreEnquiriesSELink')。点击(function(){


。 colorbox.close();

setTimeout(function(){window.location.href =enquiry.php;},500);


< blockquote>(#h2)。attr(checked,checked);

});



当btnMoreEnquiriesSELink是点击,它应该转到enquiry.php页面,而SELink的Checkbox会自动打勾。



我怎样才能实现?jquery在project.html页面中enquiry.php中的SELink Checkbox代码。代码由其他人和上次所有代码在一个页面中生成。



更新尝试解决方案



 <   script     type   =  text / javascript    src   =  js / checkbox.js >  <   / script  >   - 我把它放在两页(项目和查询)


Checkbox.js代码
< script >
函数callEnquiry(){


I got this jquery function

$('#btnMoreEnquiriesSELink').click(function() {
$.colorbox.close();
setTimeout(function(){window.location.href="enquiry.php";}, 500);
$( "#h2" ).attr( "checked", "checked" );
});

When btnMoreEnquiriesSELink is click,it should go to enquiry.php page and Checkbox for the SELink will automatically tick.

How can i achieve that?the jquery is in project.html page while the SELink Checkbox code in enquiry.php. The code make by others and last time all the code in one page.

Update Try Solution

<script type="text/javascript" src="js/checkbox.js"></script> - I put this on both page (Project and Enquiry)


Checkbox.js Code
<script>
function callEnquiry() {
    $.colorbox.close();
    setTimeout(function(){window.location.href="enquiry.php";}, 500);
    $( "#h2" ).attr( "checked", "checked" );
}
</script>

Project Page Code

<div class="btnMPPopUpLeft">&nbsp;</div> <div class="btnMPPopUpRight">
<a href="#" id="btnMoreEnquiriesAPLink" ><div class="btnMoreEnquiries">FOR MORE ENQUIRIES</div></a></div>



<script type="text/javascript">
$('#btnMoreEnquiriesSELink').click(callEnquiry);
</script>



Enquiry Code

<div class="checkbox">
<input type="checkbox" name="type[]" value="content-text" id="h2" class="checkbox" 

<?php 

for($i = 0; $i<count(@$_POST["type"]); $i++)

{

$jyef = $_POST["type"][$i];

if($jyef == 'content-text'){

echo "CHECKED";

}else{

echo "";

}

}

?>
/>
<label for="h2" class="checkboxLabel" >content-text</label>
</div><br class="clear">



P/s : i try to change attr( "checked", "true" ); but still not working

解决方案

('#btnMoreEnquiriesSELink').click(function() {


.colorbox.close();
setTimeout(function(){window.location.href="enquiry.php";}, 500);


( "#h2" ).attr( "checked", "checked" );
});

When btnMoreEnquiriesSELink is click,it should go to enquiry.php page and Checkbox for the SELink will automatically tick.

How can i achieve that?the jquery is in project.html page while the SELink Checkbox code in enquiry.php. The code make by others and last time all the code in one page.

Update Try Solution

<script type="text/javascript" src="js/checkbox.js"></script> - I put this on both page (Project and Enquiry)


Checkbox.js Code
<script>
function callEnquiry() {


这篇关于如何存储jquery点击功能并在其他页面上使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆