How to incorporate a g:link into an ordinary button?

↘锁芯ラ 提交于 2020-01-03 18:42:42

问题


In my grails application there is a view with a a g:link tag - it works fine, but the visuals are kind of awkward. Therefore, I want to disguise that g:link with an ordinary button.

I've tried a span class and input type="button" but this did not do the trick.
Side note: I don't want a g:form with an submit action.

Any help is really appreciated!


回答1:


Amit Jain's answer worked but had some problems in ie 8 & 7 (looked like some kind of style overlapping error). This solution worked in all browsers I tested

<button class="class" onClick="window.location = 'www.location.com' ">
    <g:message code="share.learnmore"></g:message>
</button>



回答2:


g:link tag does nothing but at the end creates the anchor tag. So anything that you can put inside anchor tag, so with g:link.

You can simply write. <g:link class="create" action="create"><input type="button" /></g:link>

It appears to be a button to user but does the job of g:link tag.




回答3:


I think you'll need to use some javascript on the button and the javascript onClick method to perform the linking. A good alternative is to make a nice looking image instead.

If you want to avoid javascript then just use a form with method GET

Not really grails specific but you can probably do it quite easily with g:form somehow (I'm only just getting started with Grails myself)

EDIT: Re-reading your post, the most important thing to note is that I used input type="submit" which calls the action field in the form rather than just being a button.




回答4:


I think using the link and button will actually cause the button to fire twice !! Not recomended if you are doing some work off the back of it ..



来源:https://stackoverflow.com/questions/1356894/how-to-incorporate-a-glink-into-an-ordinary-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!