我怎么知道我正确地将onChange插入表单? [英] How do I know I insert the onChange correctly into my form?

查看:81
本文介绍了我怎么知道我正确地将onChange插入表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在由php生成的选择中插入了一个onChange触发器. 但是我的最终结果是没有响应onChange函数,该函数以纯html和javascript格式完美运行. 如何调试它,以便我知道onChange函数已正确插入到我的选择标记中?

I inserted a onChange trigger into my selection that generated by php. But my final result is not responding on the onChange function which runs perfectly in pure html and javascript format. How can I debug it so that I know the onChange function has been inserted correctly into my select tag?

谢谢你

更多信息

这是实际的样子

<p class="<?php if (get_option('jr_submit_cat_required')!=='yes') : echo 'optional'; endif; ?>"><label for="job_cat"><?php _e('Job Category', 'appthemes'); ?> <?php if (get_option('jr_submit_cat_required')=='yes') : ?><span title="required">*</span><?php endif; ?></label> <?php
        $sel = 0;
        if (isset($posted['job_term_cat']) && $posted['job_term_cat']>0) $sel = $posted['job_term_cat']; 
        global $featured_job_cat_id;
        $args = array(
            'orderby'            => 'name', 
            'exclude'            => $featured_job_cat_id,
            'order'              => 'ASC',
            'name'               => 'job_term_cat',
            'hierarchical'       => 1, 
            'echo'               => 0,
            'class'              => 'job_cat',
            'selected'           => $sel,
            'taxonomy'           => 'job_cat',
            'hide_empty'         => false
        );
        $dropdown = wp_dropdown_categories( $args );
       $dropdown = str_replace('class=\'job_cat\'id=\'job_term_cat\' >','class=\'job_cat\' onchange="changeValue(this)"><option value="">'.__('Select a category&hellip;', 'appthemes').'</option>',$dropdown);
    ?></p>
echo $dropdown;

这是瓷砖

<p><label for="job_title"><?php _e('Job title', 'appthemes'); ?> <span title="required">*</span></label> <input type="text" class="text"  id="job_title" name="job_title" ></p>

这是脚本

function changeValue(obj){ document.getElementById('job_title').value= obj[obj.selectedIndex].innerHTML;
}

脚本在页脚中的位置

<p class=""><label for="cat">Category <span title="required">*</span></label> <select name="a_cat" id="a_cat" class="cat">
<option class="level-0" value="86" selected="selected">1 a</option>
<option class="level-0" value="93">2 b</option>
<option class="level-0" value="125">3 c</option>
</select>
</p>



<div id="footer">
<script type="text/javascript">
function changeValue(obj){ document.getElementById('title').value= obj[obj.selectedIndex].innerHTML;
}
</script>
</div>

上面是生成的内容和页脚,您看到什么地方不对吗?

Above is the things generated and the footer, do you see anything wrong?

推荐答案

在firefox或chrome中,您可以使用console.log('rock on!')来查看是否调用了onChange事件.

In firefox or chrome you can use console.log('rock on!') to see if your onChange event is called.

您需要在firefox中使用 Firebug 或在Chrome中使用控制台浏览器来查看结果

You'll need Firebug in firefox or the console explorer in Chrome to see the result

或者,您可以仅使用alert('here');来查看您的代码是否运行.

Alternatively, you couls only use alert('here'); to see if your code runs.

这篇关于我怎么知道我正确地将onChange插入表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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