10 Lis 2017

Odczyt atrybutów elementu w obsłudze zdarzena w javascript

<select name="banner_url" onchange="var idx=this.selectedIndex;
var value=this.options[idx].getAttribute('banner_url');
var element = document.getElementById('img_banner_url');
element.setAttribute('src', value); element.style.display='block'">


!{section name=ii loop=$data}!
  !{capture assign=banner_url}!http://kody.wig.pl/!{/capture}!
  <option value="!{$banner_url}!" banner_url="!{$banner_url}!">
  !{$data[ii].name}! ---> !{$banner_url}!</option>
!{/section}!

</select>
<br><br>

<img src="" id="img_banner_url" style="display:none">
26 Lis 2010

Odczyt atrybutów diva

function get_idx(_this_) {
  alert(_this_.id);
  let idx;
  idx=_this_.parentNode.parentNode.firstChild.getAttribute('d_idx');
  alert(idx);
  idx=_this_.parentNode.parentNode.firstChild.
    nextSibling.
    getAttribute('d_idx');
  alert(idx);
  return false;
}
.a { width: 200px; border: 1px solid; height: 40px; float: left; }
.b,.c { border: 1px solid; width: 40px; height: 40px; float: left; }
<div d_idx="1">
  <div d_idx="2">test 123456</div>
  <div d_idx="3">123</div>
  <div><a id="test1" href="#" onClick="get_idx(this)">usuń</a></div>
</div>