onclick

js修改元素的属性

时间秒杀一切 提交于 2019-12-02 18:55:00
<script type="text/javascript"> //给id为nice的元素 添加title属性并赋值为"测试title" function addTitle(){ document.getElementById('nice').setAttribute("title","测试title"); } //给id为nice的元素 删除 title属性 function delTitle(){ document.getElementById('nice').removeAttribute("title"); } //获取id为nice的元素 title属性的值 function getTitle(){ var value=document.getElementById('nice').getAttribute("title"); alert('title的属性值为:'+value); } //jq方式删除、设置元素属性,为了更加形象些对比,这里采用嵌入式方式,没有进行js html分离 function a(){ alert('测试jq添加onclick属性'); } //jq方式给id为nice的元素 添加onclick="a();"de 属性 function jqAddOnclick(){ $("#nice").attr("onclick","a();"); } /

How to Set OnClick attribute with value containing function in ie8?

我的梦境 提交于 2019-12-02 18:52:08
My goal is to change the onclick attribute of a link. I can do it successfully, but the resulting link doesn't work in ie8. It does work in ff3. For example, this works in Firefox 3, but not IE8. Why? <p><a id="bar" href="#" onclick="temp()">click me</a></p> <script> doIt = function() { alert('hello world!'); } foo = document.getElementById("bar"); foo.setAttribute("onclick","javascript:doIt();"); </script> You don't need to use setAttribute for that - This code works (IE8 also) <div id="something" >Hello</div> <script type="text/javascript" > (function() { document.getElementById("something")

Mutiple buttons with the same name showing different divs

谁说我不能喝 提交于 2019-12-02 18:08:03
问题 I have a large amount of buttons all used to display a div before it, my question is instead of having 20 different javascript functions which all do the same thing, is it possible to do with one? By default i have the display set to none in the CSS. HTML: <div class="col-lg-6 event-title"> <span>Special Olympics Unified Snowboarding Final</span> <dd>SLOPESTYLE</dd> <div id ="#dropdown"> <h6>2016 RESULTS</h6> <p> GOLD - Chris Klug & Henry Meece<br> SILVER - Danny Davis & Zach Elder<br> BRONZE

Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#

坚强是说给别人听的谎言 提交于 2019-12-02 18:06:50
问题 This isn't working: Response.Write("<a href=view.aspx?type="+Content+"onclick=\"Delete('"+f+"')\"> DELETE </a>"); <script language="javascript" type="text/javascript"> function Delete(path) { path1 = unescape(path); var myObject = new ActiveXObject("Scripting.FileSystemObject"); var myFolder = myObject.GetFolder(path1); myFolder.Delete(); alert("Welcome"); } </script> But this worked. Response.Write("<a href=view.aspx?type="+Content+"onclick=\"Delete()\"> DELETE </a>"); <script language=

Onclick event for li with javascript in asp.net mvc

北慕城南 提交于 2019-12-02 18:03:25
问题 <ul> @foreach (var item in Model.Users.Where(s => s.DepartmentId == 3)) { <li> @Ajax.ActionLink(item.UserName, "Index", new { item.Id }, new AjaxOptions() { HttpMethod = "Get" }); </li> } </ul> How can ı get item.Id if i onclick item.username with javascript ? I thought give to attribute to "li onclick".but i dont know there is better solution here or not ? 回答1: You could use a standard link and data-* attribute: <ul> @foreach (var item in Model.Users.Where(s => s.DepartmentId == 3)) { <li>

How to toggle font awesome icon on click?

て烟熏妆下的殇ゞ 提交于 2019-12-02 17:56:18
I am using font awesome 'plus' icon on expandable categories list items. When they are in expanded state i want to show a 'minus' sign' HTML <ul id="category-tabs"> <li><a href="javascript:void"><i class="fa fa-fw"></i>Category 1</a> <ul> <li><a href="javascript:void">item 1</a></li> <li><a href="javascript:void">item 2</a></li> <li><a href="javascript:void">item 3</a></li> </ul> </li> </ul> Jquery $('#category-tabs li a').click(function(){ $(this).next('ul').slideToggle('500'); }); You can toggle the class of the i element within the clicked anchor like <i class="fa fa-plus-circle"></i> then

javascript onclick increment number

ε祈祈猫儿з 提交于 2019-12-02 17:47:24
With javascript, how can I do it so when i click a form button it adds 1 to a number? The number it increments could be in a form text field or something. Obviously it'd be on onclick but I'm not sure of the code. Since you gave me nothing to start on, here is a simple example. jsFiddle Example implementation: function incrementValue() { var value = parseInt(document.getElementById('number').value, 10); value = isNaN(value) ? 0 : value; value++; document.getElementById('number').value = value; } Example Html <form> <input type="text" id="number" value="0"/> <input type="button" onclick=

jQuery click won't work with new infinite scroll elements

旧街凉风 提交于 2019-12-02 17:41:45
问题 On my page, I have a list with items and you can click on a "View More" button which shows you more information about this topic. This click function is in jQuery on an other page. I've implemented an infinite scroller on this page, but now the button "View More" doesn't work on the new elements, only on the first element. FYI: I didn't code this application, my task is just to add the infinite scroll. I've searched the web about this issue and I've read a few times this might be because the

change background color of div

◇◆丶佛笑我妖孽 提交于 2019-12-02 17:14:26
问题 this is so simple and I searched but couldn't find the exact answer. All I want to do is have a div that will change color when you click a link. I want to have about 3 or 4 color choices. How do I do it? Thanks! 回答1: Heres a quick solutions <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title

how to pass this element to javascript onclick function and add a class to that clicked element

孤街醉人 提交于 2019-12-02 16:56:16
I had an html navigation code as below function Data(string) { //1. get some data from server according to month year etc., //2. unactive all the remaining li's and make the current clicked element active by adding "active" class to the element $('.filter').removeClass('active'); $(this).addClass('active'); } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="row" style="padding-left:21px;"> <ul class="nav nav-tabs" style="padding-left:40px;"> <li class="active filter"><a href="#month" onclick="Data('month')">This Month</a></li> <li class=