문제

I'm developing a web app in grails and I have my gsp, and my .js file, I want to check if when I change a value of my combobox I can access to the function, but nothing happens... these are my codes:

javascript [dynamic.js]:

function cmbFilters(){
alert("Hello");
}

GSP [numberJobs.gsp]:

<a>Filter by :</a> <g:select id="cmbFilterBy" name="cmbFilterBy"  
 onchange="cmbFilters()" from="${['None','Name', 'Owner', 'Description', 'Status', 
'Cron   Expression']}"></g:select>

and in my Application Resources.groovy i have this:

numberJobs{
    resource url:'css/custom.css'
    resource url:'js/dynamic.js'
}
도움이 되었습니까?

해결책

g:select doesn't accept an onchange attribute, and the g:select tag will be replaced by HTML.

If you view source on the page you should not see the onchange set on the real html select.

What you can do is attach a listener to the change event for that select.

Example using jQuery

$('#cmbFilterBy').on( "change", function(){ cmbFilters() } );

Here is a simple fiddle.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top