简体   繁体   中英

Why javascript function inside new page is not working?

I have options page which opens with this:

<li class="small-icon options-panel"><a class='options-page' href="{TRESNJAPANEL_LINK}" 
title="Tresnja Options Panel" role="menuitem" onclick="window.open('{TRESNJAPANEL_LINK}', 
'newwindow', 'width=300, height=250, resizable=yes , 
scrollbars=yes'); return false;"><i class="fa fa-diamond" 
aria-hidden="true"></i>Tresnja Options Panel</a></li>

so when i open options page i have some options and functions with checkbox, inputs etc...

and i have function:

function stickyheaddsadaer(obj) {
  if($(obj).is(":checked")){
    alert("Yes checked"); //when checked
    $("#page-header-inner").addClass("sticky");
  }else{
    alert("Not checked"); //when not checked
  }

}

<input type="checkbox" name="TT_sticky_header" id="TT_sticky_header_function" 
value="{TT_sticky_header}" onclick="stickyheaddsadaer()"/>

this function only works inside options page, because when i click save and exit options page, it does not work on normal page...

or if i put this function including input type="checkbox" outside options page, then again works....

please help me what i need to do get working javascrip inside options page ?

Thank you

You have missed this inside stickyheaddsadaer() and its better to use onchange not onclick .

use this:

<input type="checkbox" name="TT_sticky_header" id="TT_sticky_header_function" 
value="{TT_sticky_header}" onchange="stickyheaddsadaer(this)"/>

instead of:

<input type="checkbox" name="TT_sticky_header" id="TT_sticky_header_function" 
    value="{TT_sticky_header}" onclick="stickyheaddsadaer()"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM