当用户点击按钮时,我需要更改data-matchId
值。我可以获得点击价值但不能将其设置为data-matchId
。
HTML部分:
<script id="betradar" type="text/javascript" data-matchId="" src="http://cs.betradar.com/ls/widgets/?/universalsoftwaresolutions/tr/Europe:Istanbul/widgetloader/widgets"></script>
JavaScript部分:
$('.livemenumatch').click(function() {
clearInterval(refreshIntervalId);
var id = $(this).attr('data-id');
var betradar = $(this).attr('data-betradar');
localStorage.setItem("lastid", id);
$.ajax({
url: '<?php echo site_url('canli'); ?>/' + id,
type: 'POST',
data: { 'submit': true },
success: function(data) {
$("#matchDetails").html(data);
$("#betradar").attr('data-matchId' , betradar);
},
});
var lastid = localStorage.getItem('lastid', lastid);
refreshIntervalId = setInterval(function() {
refreshDiv(lastid)
}, 3000);
});
我知道,给脚本标签赋予id值可能是愚蠢的,但我尝试了几种方法,无法找到任何有关它的解决方案。例如;我试图在成功后返回HTML(请检查JS代码),但它也失败了。
提前致谢。
编辑1:
我尝试了另一种解决方法,现在我将HTML部分更改为:
<div id="track"></div>
将JavaScript部分更改为:
var betradar = 'somemanualid';
$("#track").html('<script type="text/javascript" data-matchId="'+ betradar +'" src="http://cs.betradar.com/ls/widgets/?/universalsoftwaresolutions/tr/Europe:Istanbul/widgetloader/widgets">');
现在,它给小部件带来了错误。这很奇怪,因为当我把
<script type="text/javascript" data-matchId="someidhere" src="http://cs.betradar.com/ls/widgets/?/universalsoftwaresolutions/tr/Europe:Istanbul/widgetloader/widgets">
直接参与HTML,工作完美。
编辑3:
我正在分享所有HTML和JS部分:
live.php
页面:
<body style="">
<div id="loading" style="display: none;">
<span class="imgload"></span>
</div>
<!-- Header -->
<?php $this -> load -> view('user/headerMenu'); ?>
<!-- End of Header -->
<!-- Content -->
<div class="content-pro shade">
<div class="content-pro3">
<div class="content-row">
<!-- Left -->
<div class="content-left">
<div id="liveMenu">
</div>
</div>
<!-- Center -->
<div class="lmt-container" style="width: 98%"></div>
<div id="matchDetails">
</div>
<!-- End of Center -->
<!-- Right -->
<div class="content-right">
<div id="coupon_block">
<div class="kupon-pro-fixed">
<div class="kupon-pro">
<div class="loading">
<div class="imgload"></div>
</div>
<!-- Kupon Title -->
<div class="kupon-titlewrap bordertop">
<div class="kupon-title bordertop">
<span class="glyphicon glyphicon-list"></span><h1>Bahis Kuponu</h1>
<a onclick="setCouponPosition(this);" class="change-static" title="Kuponu sabitle"></a>
<span class="badge"><span id="coupon_count"></span> Seçim</span>
</div>
</div>
<!-- // Kupon Title -->
<!-- Kupon Empty -->
<div class="kupon-pro-empty borderbottom">
<p class="pad10">
<span class="glyphicon glyphicon-info-sign font12"></span> Bahis yapmak için bir seçim yapmanız gerekir
</p>
</div>
<!-- // Kupon Empty -->
</div>
</div>
</div>
<div class="right-area">
</div>
</div>
<!-- End of Right -->
<span id="lbl_collapse" style="display:none;">Tümünü Kapat</span>
<span id="lbl_expand" style="display:none;">Tümünü Aç</span>
<span id="lbl_betgroup" style="display:none;">Bahis Grubu Seçin</span>
<span id="lbl_betgroupall" style="display:none;">Bütün Bahisler</span>
<span id="lbl_game" style="display:none;">Oyun</span>
<span id="lbl_all" style="display:none;">Hepsi</span>
</div>
</div>
</div>
<!-- End of Content -->
<script type="text/javascript">
SRLive.addWidget('widgets.lmts', {
container: '.lmt-container',
showPitch: 'true',
showScoreboard: 'true',
showMomentum: 'true',
sidebarLayout: 'dynamic'// 'dynamic' | 'bottom'>
});
</script>
<script type="text/javascript">
$(document).ready(
function() {
setInterval(function() {
$.ajax({
url: '<?php echo site_url('canliMenu'); ?>/',
type: 'GET',
data : "",
success: function(data)
{
if(data!=null)
$("#liveMenu").html(data);
},
error: function (data)
{
console.log(data);
}
})}, 1000);
});
liveMenu.php文件:
<div class="livenow-menuwrap">
<div class="livenowalt-title bordertop">
<h1>Şu An Canlı</h1><span class="badge">24</span>
</div>
<div class="livenowmenu-content">
<ul id="livemenu" class="navprolivenowalt">
<li id="lvm-1" class="menuc1 open sportm-order-1">
<a href="javascript:void(0)" onclick="liveMenuToggle(this)" class="live-theme1"><span class="sportmain"> <i class="sporttype1"></i></span> Futbol <span class="badge">12</span></a>
<ul id="sportm-ct-1">
<?php foreach($liveList as $countryName => $rows) { ?>
<li id="lvm-1-175" class="menuc2 active open countrym-order-9999">
<a href="javascript:void(0)" onclick="liveMenuToggle(this)"><span class="flagmain"><i class="flag115"></i></span> <?php echo $countryName; ?></a>
<ul id="countrym-fix-1-175">
<?php foreach($rows as $m) { ?>
<li class="fix-season-19182" id="lvmfix-2547028">
<a data-id="<?php echo $m['matchId']; ?>" data-betradar="<?php echo $m['betradarId']; ?>" class="livemenumatch" id="lmi-2547028">
<span class="livenow-teams"><?php echo $m['homeTeam']; ?> - <?php echo $m['visitorTeam']; ?></span>
<span class="livenow-scoreinfo" id="fix-spm-2547028">
<span class="livenow-inscore"><?php echo $m['score']; ?></span>
<span class="livenow-inscore"><?php echo $m['minute']; ?></span>
<span class="livenow-inscore"><?php echo $m['timeDetail']; ?></span>
</span>
</a>
</li>
<?php }?>
</ul>
</li>
<?php }?>
</ul>
</li>
</ul>
</div>
</div>
<script type="text/javascript">
function refreshDiv(id){
$.ajax({
url: '<?php echo site_url('canli'); ?>/' + id,
type: "GET",
data : "",
success: function(data)
{
if(data!=null)
$("#matchDetails").html(data);
},
error: function (data)
{
console.log(data);
}
});
}
var refreshIntervalId;
$('.livemenumatch').click(function() {
clearInterval(refreshIntervalId);
var id = $(this).attr('data-id');
localStorage.setItem("lastid", id);
$.ajax({
url: '<?php echo site_url('canli'); ?>/' + id,
type: 'POST',
data: { 'submit': true },
success: function(data) {
$("#matchDetails").html(data);
},
});
var lastid = localStorage.getItem('lastid', lastid);
refreshIntervalId = setInterval(function() {
refreshDiv(lastid)
}, 3000);
});
</script>
liveDetail.php文件:
<div class="content-center" id="liveDiv">
<div class="livescoreboard livescoreboard36" style="" id="livescoreboard">
<div class="livescoreboard-title accordion-toggle pointer" data-toggle="collapse" data-target="#livescore-close">
<span class="live-event-league"><span class="flagmain"><i class="flag252 margin0"></i></span> <?php echo $liveDetail['country']; ?></span>
<span class="live-event-hometeam"><?php echo $liveDetail['homeTeam']; ?></span>
<span class="live-event-scorenow"><?php echo $liveDetail['score']; ?></span>
<span class="live-event-awayteam"><?php echo $liveDetail['visitorTeam']; ?></span>
<span class="live-event-start"><span class="glyphicon glyphicon-time"></span> <?php echo $liveDetail['date']; ?></span>
</div>
<div class="livescoreboard-headwrap" style="display: none;">
<div class="livescoreboard-headlink">
<ul>
<li>
<a href="javascript:void(0)" class="nohref video_lbl active" onclick="toggleVideo(this, 'graphic')"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span> Canlı Grafik</a>
</li>
<li>
<a href="javascript:void(0)" class="nohref video_lbl" onclick="toggleVideo(this, 'video')"><span class="glyphicon glyphicon-facetime-video" aria-hidden="true"></span> Canlı Video</a>
</li>
</ul>
</div>
</div>
<div class="livescoreboard-content collapse in" id="livescore-close">
<div class="lmt-container"></div>
<script type="text/javascript" data-matchId="8047580" src="http://cs.betradar.com/ls/widgets/?/universalsoftwaresolutions/tr/Europe:Istanbul/widgetloader/widgets"></script>
<script type="text/javascript">
SRLive.addWidget('widgets.lmts', {
container: '.lmt-container',
showPitch: 'true',
showScoreboard: 'true',
showMomentum: 'true',
sidebarLayout: 'dynamic'// 'dynamic' | 'bottom'>
});
</script>
</div>
</div>
<div id="divOrta">
<div class="live-event-rate-well">
<div class="live-event-actions-title">
<div class="pull-left">
<div class="live-events-actions-column">
<ul>
<li>
<a onclick="openAllFixture()"><span class="glyphicon glyphicon-chevron-down"></span> Tümünü Aç</a>
</li>
<li>
<a onclick="closeAllFixture()"><span class="glyphicon glyphicon-chevron-up"></span> Tümünü Kapat</a>
</li>
</ul>
</div>
</div>
</div>
<div class="live-event-bettype-title" style="display: none;">
<span class="pull-left">undefined</span><span class="pull-right"><a class="close-icon-sm clsoe-white" onclick="closeGroupMarketLine()"></a></span>
</div>
<div class="double-view">
<?php foreach($liveDetail['odds'] as $odds) { ?>
<div class="sub-main-well-live btg-order-1" id="fx-btg-<?php echo $odds['orderNo']; ?>">
<div class="sub-rate-title" data-toggle="collapse" data-target="#ac-kapa-sub-rate-<?php echo $odds['orderNo']; ?>">
<span><?php echo $odds['oddType']; ?></span>
</div>
<div class="close-open in" id="ac-kapa-sub-rate-<?php echo $odds['orderNo']; ?>">
<div class="sub-fixturelayout">
<ul>
<li>
<div class="fixturelayout-rate">
<ul>
<li id="btg-odd-<?php echo $odds['orderNo']; ?>">
<?php echo $odds['odd']; ?>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</div>
<?php }?>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
我认为它的jquery没有执行你的脚本。尝试纯粹的js
t = document.getElementById("track")
var tag = document.createElement('script');
tag.setAttribute("data-matchId", "somethingHere");
tag.setAttribute("id","dynamic-script");
tag.src = "http://cs.betradar.com/ls/widgets/?/universalsoftwaresolutions/tr/Europe:Istanbul/widgetloader/widgets";
t.appendChild(tag);
看看这是否有帮助
答案 1 :(得分:0)
不要加载matchId betradar,只需将参数添加到addWidget。
而不是:
<script type="text/javascript" data-matchId="id" src="http://cs.betradar.com/ls/widgets/?/universalsoftwaresolutions/tr/Europe:Istanbul/widgetloader/widgets">
使用:
<script type="text/javascript" src="http://cs.betradar.com/ls/widgets/?/universalsoftwaresolutions/tr/Europe:Istanbul/widgetloader/widgets">
然后做:
SRLive.addWidget('widgets.lmts', {
container: '.lmt-container',
showPitch: 'true',
showScoreboard: 'true',
showMomentum: 'true',
sidebarLayout: 'dynamic',
matchId: <<yourIdHere>>
});