从代码隐藏中设置 HTML5 可拖动属性不起作用?



我有一个从代码隐藏生成的表,并尝试将HTML5可拖动属性应用于其表单元格。

TabCell.Attributes["draggable"] = "true";

上面成功应用了该属性,因为我可以在检查元素中看到它,但元素不会拖动。

有没有人知道为什么会这样?

我必须在元素上设置可拖动的JQuery。

$('#myid').draggable();

在服务器端应用属性时不起作用

从您的问题中还不完全清楚 TabCell 是什么,但假设它只是一个您想要做的客户端 HTML 元素:

TabCell.setAttribute("draggable", "true");

你不需要 JQuery。 下面是一些带有两个选项卡的代码,它们都可以通过设置上述属性来拖动。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<style>
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
}
.tab button:hover {
background-color: #ddd;
}
</style>
</head>
<body>
<div class="tab">
<button id="TabCell1">Tab1 Header</button>
<button id="TabCell2">Tab2 Header</button>
</div>
<script>
window.onload = () => {
var TabCell = document.getElementById('TabCell1');
TabCell.setAttribute("draggable", "true");
var TabCell2 = document.getElementById('TabCell2');
TabCell2.setAttribute("draggable", "true");
};
</script>
</body>
</html>

最新更新