这是我的代码, 如何在form_input()codeigniter ??
中放置javascript数据属性$experience=array(
'name'=>'experience',
'class'=>'slider tags',
'id'=>'experience',
'data-slider-min'=>1,
'data-slider-max'=>15,
'data-slider-step'=>1,
'data-slider-value'=>[5,10]
);
echo form_input($experience); ?>
答案 0 :(得分:1)
查看此代码可能有助于您克服此问题
<?php
$experience=array(
'name'=>'experience',
'class'=>'slider tags',
'id'=>'experience',
'data-slider-min'=>0,
'data-slider-max'=>15,
'data-slider-step'=>1,
'data-slider-value'=>['5','10'],
'value'=>3,4
);
echo form_input($experience);
?>
答案 1 :(得分:0)
您是否尝试过将JS属性移动到用于创建输入的$ experience变量中?
$experience=array(
'name'=>'experience',
'class'=>'slider tags',
'id'=>'experience',
'data-slider-min' => 1,
'data-slider-max' => 15,
);
等...
答案 2 :(得分:0)
// HTML代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="main.js"></script>
</head>
<body>
<li class="item" data-done-state="true">Erster Eintrag</li>
<li class="item" data-done-state="false">Zweiter Eintrag</li>
<li class="item" data-done-state="true">Dritter Eintrag</li>
</body>
</html>
// CSS代码
li {
background-color: khaki;
margin: 2px;
padding: 2px;
}
[data-done-state="true"] {
text-decoration: line-through;
}
// JS代码
window.onload = function() {
const nodes = document.querySelectorAll(".item");
for (const node of nodes) {
node.addEventListener("click", function(elem) {
switchDoneState(elem);
});
}
};
function switchDoneState(elem) {
const isDone = JSON.parse(elem.target.getAttribute("data-done-state"));
elem.target.setAttribute("data-done-state", !isDone);
}